package off_trial

import (
	"bp/internal/service/com/offer"
	offTrialGrpc "bp/rpc/gen/mwebapi/off_trial"
	messageGrpc "bp/rpc/gen/shared/message"
)

// 以下 pb -> entity
type OffTrialItemPtrPbToEntityFunc func(*offTrialGrpc.TrialItemEntity) *offer.ToTrialItem
type OffTrialItemPtrArrayPbToEntityFunc func([]*offTrialGrpc.TrialItemEntity) []*offer.ToTrialItem
type OffTrialOwnerPtrPbToEntityFunc func(*offTrialGrpc.TrialOwnerEntity) *offer.ToTrialOwner
type OffTrialOwnerPtrArrayPbToEntityFunc func([]*offTrialGrpc.TrialOwnerEntity) []*offer.ToTrialOwner

// ConvOffTrialItemPtrPbToEntity get func of *offTrialGrpc.TrialItemEntity => *offer.ToTrialItem
func (s *OffTrialMWebApiImp) ConvOffTrialItemPtrPbToEntity() OffTrialItemPtrPbToEntityFunc {
	return func(ptr *offTrialGrpc.TrialItemEntity) *offer.ToTrialItem {
		if ptr == nil {
			return nil
		}
		return &offer.ToTrialItem{
			DetailID:   ptr.SceneDetailId,
			DetailCnt:  ptr.SceneDetailCnt,
			ItemID:     ptr.ItemId,
			ItemSpecID: ptr.ItemSpecId,
			ItemPrice:  ptr.ItemPrice,
		}
	}
}

// ConvOffTrialItemPtrArrayEntityToPb get func of []*offTrialGrpc.TrialItemEntity => []*offer.ToTrialItem
func (s *OffTrialMWebApiImp) ConvOffTrialItemPtrArrayPbToEntity() OffTrialItemPtrArrayPbToEntityFunc {
	return func(ptrs []*offTrialGrpc.TrialItemEntity) (vPtrs []*offer.ToTrialItem) {
		for _, ptr := range ptrs {
			vPtrs = append(vPtrs, s.ConvOffTrialItemPtrPbToEntity()(ptr))
		}
		return
	}
}

// ConvOffTrialOwnerPtrPbToEntity get func of *offTrialGrpc.TrialOwnerEntity => *offer.ToTrialOwner
func (s *OffTrialMWebApiImp) ConvOffTrialOwnerPtrPbToEntity() OffTrialOwnerPtrPbToEntityFunc {
	return func(ptr *offTrialGrpc.TrialOwnerEntity) *offer.ToTrialOwner {
		if ptr == nil {
			return nil
		}
		return &offer.ToTrialOwner{
			OwnerID:          ptr.OwnerId,
			MustUseCouponSns: ptr.CouponSns,
			ItemPtrs:         s.ConvOffTrialItemPtrArrayPbToEntity()(ptr.TrialItems),
		}
	}
}

// ConvOffTrialItemPtrArrayEntityToPb get func of []*offTrialGrpc.TrialOwnerEntity => []*offer.ToTrialOwner
func (s *OffTrialMWebApiImp) ConvOffTrialOwnerPtrArrayPbToEntity() OffTrialOwnerPtrArrayPbToEntityFunc {
	return func(ptrs []*offTrialGrpc.TrialOwnerEntity) (vPtrs []*offer.ToTrialOwner) {
		for _, ptr := range ptrs {
			vPtrs = append(vPtrs, s.ConvOffTrialOwnerPtrPbToEntity()(ptr))
		}
		return
	}
}

// 以下 entity -> pb

type OffTrialItemPtrEntityToPbFunc func(*offer.TrialedItem) *offTrialGrpc.OffTrialItemEntity
type OffTrialItemPtrArrayEntityToPbFunc func([]*offer.TrialedItem) []*offTrialGrpc.OffTrialItemEntity

// ConvOffTrialItemPtrEntityToPb get func of *offer.TrialedItem => *offTrialGrpc.OffTrialItemEntity
func (s *OffTrialMWebApiImp) ConvOffTrialItemPtrEntityToPb() OffTrialItemPtrEntityToPbFunc {
	return func(ptr *offer.TrialedItem) *offTrialGrpc.OffTrialItemEntity {
		if ptr == nil {
			return nil
		}
		return &offTrialGrpc.OffTrialItemEntity{
			SceneDetailId:  ptr.SceneDetailID,
			SceneDetailCnt: ptr.SceneDetailCnt,
			ItemId:         ptr.ItemID,
			ItemSpecId:     ptr.ItemSpecID,
			ItemPrice:      ptr.ItemPrice,
			Off:            ptr.Off,
			Cnt:            ptr.Cnt,
		}
	}
}

// ConvOffTrialItemPtrArrayEntityToPb get func of []*offer.TrialedItem => []*offTrialGrpc.OffTrialItemEntity
func (s *OffTrialMWebApiImp) ConvOffTrialItemPtrArrayEntityToPb() OffTrialItemPtrArrayEntityToPbFunc {
	return func(ptrs []*offer.TrialedItem) (vPtrs []*offTrialGrpc.OffTrialItemEntity) {
		for _, ptr := range ptrs {
			vPtrs = append(vPtrs, s.ConvOffTrialItemPtrEntityToPb()(ptr))
		}
		return
	}
}

type OffTrialOfferItemPtrEntityToPbFunc func(*offer.TrialedOfferItem) *offTrialGrpc.OffTrialOfferItemEntity
type OffTrialOfferItemPtrArrayEntityToPbFunc func([]*offer.TrialedOfferItem) []*offTrialGrpc.OffTrialOfferItemEntity

// ConvOffTrialOfferItemPtrEntityToPb get func of *offer.TrialedOfferItem => *messageGrpc.OfferItemEntity
func (s *OffTrialMWebApiImp) ConvOffTrialOfferItemPtrEntityToPb() OffTrialOfferItemPtrEntityToPbFunc {
	return func(ptr *offer.TrialedOfferItem) *offTrialGrpc.OffTrialOfferItemEntity {
		if ptr == nil {
			return nil
		}
		return &offTrialGrpc.OffTrialOfferItemEntity{
			Off:           ptr.Off,
			OfferType:     ptr.OfferType,
			OfferItemType: ptr.OfferItemType,
			OfferItemId:   ptr.OfferItemID,
			OfferItemInfo: &messageGrpc.OffItemInfoEntity{
				Name: ptr.TrialedInfoPtr.Name,
				Desc: ptr.TrialedInfoPtr.Desc,
			},
			OffTrialItems: s.ConvOffTrialItemPtrArrayEntityToPb()(ptr.TrialedItemPtrs),
		}
	}
}

// ConvOffTrialOfferItemPtrArrayEntityToPb get func of []*offer.TrialedOfferItem => []*offTrialGrpc.OffTrialOfferItemEntity
func (s *OffTrialMWebApiImp) ConvOffTrialOfferItemPtrArrayEntityToPb() OffTrialOfferItemPtrArrayEntityToPbFunc {
	return func(ptrs []*offer.TrialedOfferItem) (vPtrs []*offTrialGrpc.OffTrialOfferItemEntity) {
		for _, ptr := range ptrs {
			vPtrs = append(vPtrs, s.ConvOffTrialOfferItemPtrEntityToPb()(ptr))
		}
		return
	}
}

type OffTrialOwnerPtrEntityToPbFunc func(*offer.TrialedOwner) *offTrialGrpc.OffTrialOwnerEntity
type OffTrialOwnerPtrArrayEntityToPbFunc func([]*offer.TrialedOwner) []*offTrialGrpc.OffTrialOwnerEntity

// ConvOffTrialOwnerPtrEntityToPb get func of *offer.TrialedOwner => *offTrialGrpc.OffTrialOwnerEntity
func (s *OffTrialMWebApiImp) ConvOffTrialOwnerPtrEntityToPb() OffTrialOwnerPtrEntityToPbFunc {
	return func(ptr *offer.TrialedOwner) *offTrialGrpc.OffTrialOwnerEntity {
		if ptr == nil {
			return nil
		}
		return &offTrialGrpc.OffTrialOwnerEntity{
			OwnerId:    ptr.OwnerID,
			Off:        ptr.Off,
			OfferItems: s.ConvOffTrialOfferItemPtrArrayEntityToPb()(ptr.TrialedOffItemPtrs),
		}
	}
}

// ConvOffTrialOfferItemPtrArrayEntityToPb get func of []*offer.TrialedOwner => []*offTrialGrpc.OffTrialOwnerEntity
func (s *OffTrialMWebApiImp) ConvOffTrialOwnerPtrArrayEntityToPb() OffTrialOwnerPtrArrayEntityToPbFunc {
	return func(ptrs []*offer.TrialedOwner) (vPtrs []*offTrialGrpc.OffTrialOwnerEntity) {
		for _, ptr := range ptrs {
			vPtrs = append(vPtrs, s.ConvOffTrialOwnerPtrEntityToPb()(ptr))
		}
		return
	}
}
